
 
import GameActions.MoveEastAction;
import GameActions.MoveNorthAction;
import GameActions.MoveSouthAction;
import GameActions.MoveWestAction;
import GameObjects.Player;

import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.action.InputActionEvent;
import com.jme.input.action.KeyNodeBackwardAction;
import com.jme.input.action.KeyNodeForwardAction;
import com.jme.input.action.KeyNodeRotateLeftAction;
import com.jme.input.action.KeyNodeRotateRightAction;
import com.jme.scene.Spatial;
 
/**
 * Input Handler. This controls a supplied spatial
 * allowing us to move it forward, backward, left and right.
 *
 */
public class ConanInputHandler extends InputHandler {
 
    /**
     * Supply the node to control and the api that will handle input creation.
     * @param node the node we wish to move
     * @param api the library that will handle creation of the input.
     */
	
	private Player ds;	
	
    public ConanInputHandler(Player _ds, String api) {
        this.ds = _ds;
        setKeyBindings(api);
        setActions(_ds);
    }
    
    public void update(float interpolation){
    	ds.resetMovementDirection();
    	super.update(interpolation);
    }
 
    /**
     * creates the keyboard object, allowing us to obtain the values of a keyboard as keys are
     * pressed. It then sets the actions to be triggered based on if certain keys are pressed (WSAD).
     * @param api
     */
    private void setKeyBindings(String api) {
        KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
 
        keyboard.set("north", KeyInput.KEY_W);
        keyboard.set("south", KeyInput.KEY_S);
        keyboard.set("east", KeyInput.KEY_D);
        keyboard.set("west", KeyInput.KEY_A);
    }
 
    /**
     * assigns action classes to triggers. These actions handle moving the node forward, backward, left, and right.
     * @param node the node to control.
     */
    private void setActions(Player _ds) {
    	MoveNorthAction north = new MoveNorthAction(_ds);
        addAction(north, "north", true);
    	MoveSouthAction south = new MoveSouthAction(_ds);
        addAction(south, "south", true);
    	MoveEastAction east = new MoveEastAction(_ds);
        addAction(east, "east", true);
    	MoveWestAction west = new MoveWestAction(_ds);
        addAction(west, "west", true);

    } 
}